package com.example.schedule.feign;

import com.example.apis.schedule.IScheduleClient;
import com.example.model.common.dtos.ResponseResult;
import com.example.model.schedule.dtos.Task;
import com.example.schedule.service.TaskService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
public class ScheduleClient implements IScheduleClient {

    @Autowired
    private TaskService taskService;

    @Override
    @PostMapping("/feign/v1/task/add")
    public ResponseResult addTask(@RequestBody Task task) {
        log.info("远程接口 scheduleClient");
        return ResponseResult.okResult(taskService.addTask(task));
    }

    @Override
    @GetMapping("/feign/v1/task/{taskId}")
    public ResponseResult cancelTask(@PathVariable("taskId") long taskId) {
        return ResponseResult.okResult(taskService.cancelTask(taskId));
    }

    @Override
    @GetMapping("/feign/v1/task/{type}/{priority}")
    public ResponseResult pull(@PathVariable("type") int type,@PathVariable("priority") int priority) {
        return ResponseResult.okResult(taskService.pull(type,priority));
    }
}
